package com.itheima.jwt;

import io.jsonwebtoken.*;

import java.util.Date;

public class JwtTest {
    public static void main(String[] args) {
//        Date date = new Date();
//        System.out.println(date);
//        long l = System.currentTimeMillis();
//        Date date1 = new Date(l);
//        System.out.println(date1);

        JwtBuilder jwtBuilder = Jwts.builder()//生成令牌
                .setId("66")//设置jwt编码
                .setSubject("黑马程序员")//设置jwt主题
                .setIssuedAt(new Date())//设置签发日期
//                .setExpiration(date1)//设置国过期时间
                .claim("roles","admin")
                .claim("company","itheima")
                .signWith(SignatureAlgorithm.HS256, "itheima");
        String compact = jwtBuilder.compact();
        System.out.println(compact);

        //解析jwt,得到其内部的数据
        Claims itheima = Jwts.parser().setSigningKey("itheima").parseClaimsJws(compact).getBody();
        System.out.println(itheima);

    }
}
